package com.example.admin.yuejian_22.Fragment;


import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;

import com.example.admin.yuejian_22.Activity.SendPhotoActivity;
import com.example.admin.yuejian_22.Adapter.ClubListAdapter;
import com.example.admin.yuejian_22.Adapter.PhotoListAdapter;
import com.example.admin.yuejian_22.Base.BaseFragment;
import com.example.admin.yuejian_22.Bean.ClubList;
import com.example.admin.yuejian_22.Bean.PhotoBean;
import com.example.admin.yuejian_22.Listener.UserListener;
import com.example.admin.yuejian_22.Model.UserModel;
import com.example.admin.yuejian_22.R;

import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class PhotoFragment extends Fragment {
    public RecyclerView recyclerView;
    private View view = null;
    private ImageButton photo_add;

    UserListener userListener = new UserListener() {
        @Override
        public void onResponse(Object beanobject) {
            recyclerView.setAdapter(new PhotoListAdapter(getActivity(),(List<PhotoBean>) beanobject));
        }
        @Override
        public void onFail(String msg) {

        }
    };
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        view =  inflater.inflate(R.layout.fragment_photo, container, false);
        photo_add = (ImageButton) view.findViewById(R.id.photo_add);
        photo_add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getActivity(), SendPhotoActivity.class);
                startActivity(intent);
            }
        });
        initRecyclerView(view);
        UserModel model = new UserModel();
        model.getPhotolist(userListener);
        return view;
    }
    public  void initRecyclerView(View view){
        recyclerView=(RecyclerView) view.findViewById(R.id.photo_list);
        recyclerView.setLayoutManager(new LinearLayoutManager(this.getActivity()));
        recyclerView.setItemAnimator(new DefaultItemAnimator());
    }

}
